/**
 * desc: 待办管理
 * author: cx
 * date: xxxx
 */

appModule.controller('StandbyManagement',
  [
    '$scope', '$document', 'api','PhoneService', 'DateFormatter', 'constant', 'TransFerence', 'dateCompareSize',
    function($scope, $document, api, PhoneService, DateFormatter, constant, TransFerence, dateCompareSize) {
      PhoneService.getExamineRecord.query(TransFerence({cPage: 1, pSize: 10})).$promise.then(function(res) {
        if (res.error_code === 0){
            $scope.msgBox = [
              {
                "num": res.data.meetApplyCount,
                "msg": "会议申请",
                "url": "#!/meeting-examine?state=1"
              },
              {
                "num": res.data.meetDataCount,
                "msg": "会议资料",
                "url": "#!/meeting-examine/data?1"
              },
              {
                "num": res.data.sponsorCount,
                "msg": "赞助申请",
                "url": "#!/meeting-sponsor-apply?state=0"
              },
              {
                "num": res.data.sponsorVoucherCount,
                "msg": "赞助凭证",
                "url": "#!/meeting-sponsor-voucher?state=0"
              }
            ]
          }
      });
      var colData = [
        {
          key: 'meetname',
          text: '会议名称',
        },
        {
          key: 'meetNum',
          text: '会议编号',
        },
        {
          key: 'type',
          text: '类型',
          template: function(val) {
            if (val !== null){
              for (var i =0; i < constant.meetingstate.length;i++){
                if (val === constant.meetingstate[i]['value']){
                    return constant.meetingstate[i]['label']
                }
              }
            }
          },
        },
        {
          key: 'examineTime',
          text: '审批时间'
        },
        {
          key: 'state',
          text: '操作记录',
          template: function(val) {
            if (val !== null){
              if (val === -1){
                var strcolor = 'color:red';
              }
              var msg = val === 1 ? '已通过' : '已拒绝';
              return '<span style="'+strcolor+'">'+msg+'</span>'
            }
          },
        },
        {
          key: 'msg',
          text: '备注',
          template: function(val) {
            if (val !== null){
              return val
            } else {
              return ''
            }
          },
        },
      ];

      $scope.option = {
        gridManagerName: 'table-demo',
        columnData: colData,
        ajax_data: api.getExamineRecord,
        query: {},
      };

      $scope.greeting = function() {
        alert();
      };

      $scope.inputForm = [
        {
          key: 'meetname',
          maintitle: '会议名称：',
        }
      ];
      $scope.inputFormdate = [
        {
          key : 'starttime',
          title: '开始时间',
          maintitle: '审批时间：',
          datemarker: true
        },
        {
          key : 'endtime',
          title: '结束时间',
        }
      ];
      var states = constant.meetingstate;
      $scope.selectForm = [
        {
          key: 'type',
          title: '会议类型：',
          option: states,
        }
      ];

      $scope.buttonForm = [
        {
          title: '查询'
        },
        {
          title: '清空',
          action: function (formData) {
            // formData = {};
            var arr = [];
            for (i in formData) {
              arr.push(i);
            }
            for (i = 0; i < arr.length; i++) {
              formData[arr[i]] = '';
            }
          }
        }
      ];
      $scope.action = function(formData) {
        var timeMsg = dateCompareSize(formData.starttime, formData.endtime);
        if (!angular.isUndefined(timeMsg)){
          if (timeMsg !== 1){
            formData.starttime = timeMsg.startTime;
            formData.endtime = timeMsg.endTime;
          } else{
            return;
          }
        } else{
          formData.starttime = '';
          formData.endtime = '';
        }
        $document.find('table')[0].GM('setQuery', formData);
      };
    }
  ]
);
